package io.renren.modules.erp.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.erp.entity.PaperInfoAndType;
import io.renren.modules.erp.entity.PaperInfoEntity;
import io.renren.modules.erp.service.PaperInfoService;



/**
 * 
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2018-07-19 22:30:09
 */
@RestController
@RequestMapping("erp/paperinfo")
public class PaperInfoController {
    @Autowired
    private PaperInfoService paperInfoService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("erp:paperinfo:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = paperInfoService.queryPage(params);

        return R.ok().put("page", page);
    }
    
    /**
     * 列表
     */
    @RequestMapping("/alllist")
    @RequiresPermissions("erp:paperinfo:list")
    public R alllist(@RequestParam Map<String, Object> params){
        List<PaperInfoAndType> res = paperInfoService.queryAllList(params);

        return R.ok().put("list", res);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{paperInfoId}")
    @RequiresPermissions("erp:paperinfo:info")
    public R info(@PathVariable("paperInfoId") Long paperInfoId){
        PaperInfoEntity paperInfo = paperInfoService.selectById(paperInfoId);

        return R.ok().put("paperInfo", paperInfo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("erp:paperinfo:save")
    public R save(@RequestBody PaperInfoEntity paperInfo){
        paperInfoService.insert(paperInfo);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("erp:paperinfo:update")
    public R update(@RequestBody PaperInfoEntity paperInfo){
        ValidatorUtils.validateEntity(paperInfo);
        paperInfoService.updateAllColumnById(paperInfo);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("erp:paperinfo:delete")
    public R delete(@RequestBody Long[] paperInfoIds){
        paperInfoService.deleteBatchIds(Arrays.asList(paperInfoIds));

        return R.ok();
    }

}
